<script>
export default {
  name: "Quit",
  data(){
    return {
      accName:'',
      isFullScreen:0,  //0未进入全屏，1全屏模式
      full_screen_tag:'全屏',
    }
  },
  created() {
    this.getAcc();
  },
  methods:{
      getAcc(){
        this.accName = sessionStorage.getItem("accRealName");
      },

      //退出答题
      exit(){
        this.$confirm('此操作将放弃此次作答，退出答题系统, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$router.push("acc_login")
        }).catch(() => {});
      },

    //进入全屏
      enterFullScreen(element) {
        try {
          if (element.requestFullscreen) {
            element.requestFullscreen();
          } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
          } else if (element.webkitRequestFullscreen) {
            element.webkitRequestFullscreen();
          } else if (element.msRequestFullscreen) {
            element.msRequestFullscreen();
          }
        } catch (error) {
          console.error("无法全屏:", error);
        }
      },

    //退出全屏
    exitFullScreen() {
      try {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.webkitExitFullscreen) {
          document.webkitExitFullscreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } catch (error) {
        console.error("Failed to exit full screen:", error);
      }
    },







      full_screen(){
        var elem = document.documentElement;
        if(this.isFullScreen==0){
            //设置全屏状态
            this.isFullScreen = 1;
            this.full_screen_tag = '退出全屏'
            // 使整个页面进入全屏
            if (elem.requestFullscreen) {
              elem.requestFullscreen();
            } else if (elem.mozRequestFullScreen) { /* Firefox */
              elem.mozRequestFullScreen();
            } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
              elem.webkitRequestFullscreen();
            } else if (elem.msRequestFullscreen) { /* IE/Edge */
              elem.msRequestFullscreen();
            }
        }else{
          //设置全屏状态
          this.isFullScreen = 0;
          this.full_screen_tag = '全屏'
          //退出全屏
          if (document.exitFullscreen) {
            document.exitFullscreen();
          } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
          } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
          } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
          }
        }
      }

  }
}
</script>

<template>
  <div>
    <el-row>
      <el-col>
          <el-button type="success" @click="full_screen" style="font-size: 25px;">
            {{ full_screen_tag }}
          </el-button>
            <slot></slot>
          <el-button @click="exit" type="danger" style="font-size: 25px;">
            退出
          </el-button>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>

</style>